package com.kl.rabbitmqprovider.test;

import java.util.Arrays;
import java.util.Scanner;

public class Main2 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        Node[] nodes = new Node[n];
        for (int i = 0; i < n; i++) {
            String str = scanner.next();
            nodes[i] = new Node(str, change(str), i);
        }
        Arrays.sort(nodes);
        int i = 0;
        while (i < n) {
            System.out.println(nodes[i].str1);
            i++;
        }
    }

    private static String change(String str) {
        StringBuilder builder = new StringBuilder(str);
        int n = builder.length() - 1;
        for (int i = 0, j = n; i < j; i++, j--) {
            if (builder.charAt(i) > builder.charAt(j)) {
                char c = builder.charAt(i);
                builder.setCharAt(i, builder.charAt(j));
                builder.setCharAt(j, c);
            }
        }
        return builder.toString();
    }

    static class Node implements Comparable<Node> {
        public String str1;
        public String str2;
        public int weight;

        public Node(String str1, String str2, int weight) {
            this.str1 = str1;
            this.str2 = str2;
            this.weight = weight;
        }

        @Override
        public int compareTo(Node o) {
            return (str2.compareTo(o.str2) != 0) ? str2.compareTo(o.str2) : weight - o.weight;
        }
    }
}
